/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package consistency_check.DAO;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.faces.context.FacesContext;
import login.bean.LoginBean;

/**
 *
 * @author chucho
 */
public class ConsistencyCheckDAO {
     Connection connection;
     private LoginBean lb ;

    public ConsistencyCheckDAO() {
        lb = (LoginBean) FacesContext.getCurrentInstance()
                .getExternalContext().getSessionMap().get("loginBean");
        this.connection = lb.getCurrentConnection();
    }
             
     public ResultSet checkTable(String database,String table, boolean quick)throws SQLException{
         Statement statement = connection.createStatement();
         String sql = "CHECK TABLE "+ database + "."+ table +" ";
         if(quick){
             sql += "QUICK";
         }
         return statement.executeQuery(sql);
     }
     
     public ResultSet analizeTable(String table) throws SQLException{
         Statement statement = connection.createStatement();
         String sql = "ANALYZE TABLE "+ table;
         return statement.executeQuery(sql);
     }
     
}
